"""
Author: 陈荣建 283431730@qq.com
Date: 2023-12-04 10:54:44
LastEditors: 陈荣建 283431730@qq.com
LastEditTime: 2023-12-18 15:43:32
FilePath: /YYGateStrategy/futures.py
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
"""
# !/usr/bin/env python
# coding: utf-8
import logging
import time
import json
import os
import threading
from multiprocessing import Process

from YYGateStrategy import YYGateWangge


from decimal import Decimal as D, ROUND_UP, getcontext

from gate_api import (
    ApiClient,
    Configuration,
    FuturesApi,
    FuturesOrder,
    Transfer,
    WalletApi,
)
from gate_api.exceptions import GateApiException

from config import RunConfig

from futures_toolbox import (
    getPercentDepth,
    getScaleOfPendingOrders,
    totalSize,
    updateContractList,
    lastPrice,
    getEarningsFromWangge
)

logger = logging.getLogger(__name__)


def creat_wangge(
    contract,
    singleAmount,
    interval,
    api_key,
    api_secret,
    host_used,
    transactionPoint=0.004,
):
    YYGateWangge(
        contract,
        singleAmount,
        interval,
        api_key,
        api_secret,
        host_used,
        transactionPoint,
    )


def futures_demo(run_config):

    # type: (RunConfig) -> None
    settle = "usdt"

    # 获取当前脚本文件的绝对路径
    script_path = os.path.abspath(__file__)
    # 获取当前脚本所在的目录
    script_directory = os.path.dirname(script_path)
    # 改变当前工作目录到脚本所在的目录
    os.chdir(script_directory)

    # Initialize API client
    # Setting host is optional. It defaults to https://api.gateio.ws/api/v4
    # config = Configuration(
    #     key=run_config.api_key, secret=run_config.api_secret, host=run_config.host_used
    # )
    # futures_api = FuturesApi(ApiClient(config))

    # updateContractList(settle, futures_api)
    # return

    wg_list = []

    # wg = YYGateWangge(
    #     "PEPE2_USDT",
    #     2,
    #     "0.00000000001",
    #     run_config.api_key,
    #     run_config.api_secret,
    #     run_config.host_used,
    #     0.004,
    # )
    # wg_list.append(wg)

    wg2 = YYGateWangge(
        "ETH_USDT",
        1,
        "0.1",
        run_config.api_key,
        run_config.api_secret,
        run_config.host_used,
        0.004,
    )
    wg_list.append(wg2)

    wg3 = YYGateWangge(
        "WLD_USDT",
        1,
        "0.001",
        run_config.api_key,
        run_config.api_secret,
        run_config.host_used,
        0.004,
    )
    wg_list.append(wg3)

    # wg4 = YYGateWangge(
    #     "LINK_USDT",
    #     1,
    #     "0.0001",
    #     run_config.api_key,
    #     run_config.api_secret,
    #     run_config.host_used,
    #     0.008,
    # )
    # wg_list.append(wg4)

    wg5 = YYGateWangge(
        "DOGE_USDT",
        5,
        "0.00001",
        run_config.api_key,
        run_config.api_secret,
        run_config.host_used,
        0.004,
    )
    wg_list.append(wg5)

    # wg6 = YYGateWangge(
    #     "ORDI_USDT",
    #     1,
    #     "0.01",
    #     run_config.api_key,
    #     run_config.api_secret,
    #     run_config.host_used,
    #     0.008,
    # )
    # wg_list.append(wg6)

    wg7 = YYGateWangge(
        "SHIB_USDT",
        30,
        "0.00000001",
        run_config.api_key,
        run_config.api_secret,
        run_config.host_used,
        0.004,
    )
    wg_list.append(wg7)

    # wg8 = YYGateWangge(
    #     "XRP_USDT",
    #     2,
    #     "0.001",
    #     run_config.api_key,
    #     run_config.api_secret,
    #     run_config.host_used,
    #     0.005,
    # )
    # wg_list.append(wg8)

    wg9 = YYGateWangge(
        "BONK_USDT",
        1,
        "0.000000001",
        run_config.api_key,
        run_config.api_secret,
        run_config.host_used,
        0.026,
    )
    wg_list.append(wg9)

    # wg10 = YYGateWangge(
    #     "BTC_USDT",
    #     3,
    #     "10",
    #     run_config.api_key,
    #     run_config.api_secret,
    #     run_config.host_used,
    #     0.004,
    # )
    # wg_list.append(wg10)

    # wg11 = YYGateWangge(
    #     "AVAX_USDT",
    #     1,
    #     "0.001",
    #     run_config.api_key,
    #     run_config.api_secret,
    #     run_config.host_used,
    #     0.018,
    # )
    # wg_list.append(wg11)

    # wg12 = YYGateWangge(
    #     "ARB_USDT",
    #     5,
    #     "0.001",
    #     run_config.api_key,
    #     run_config.api_secret,
    #     run_config.host_used,
    #     0.004,
    # )
    # wg_list.append(wg12)

    # wg13 = YYGateWangge(
    #     "BNB_USDT",
    #     30,
    #     "0.01",
    #     run_config.api_key,
    #     run_config.api_secret,
    #     run_config.host_used,
    #     0.003,
    # )
    # wg_list.append(wg13)

    # wg14 = YYGateWangge(
    #     "SOL_USDT",
    #     1,
    #     "0.01",
    #     run_config.api_key,
    #     run_config.api_secret,
    #     run_config.host_used,
    #     0.05,
    # )
    # wg_list.append(wg14)

    # wg15 = YYGateWangge(
    #     "SUI_USDT",
    #     5,
    #     "0.001",
    #     run_config.api_key,
    #     run_config.api_secret,
    #     run_config.host_used,
    #     0.004,
    # )
    # wg_list.append(wg15)

    # wg16 = YYGateWangge(
    #     "APT_USDT",
    #     10,
    #     "0.01",
    #     run_config.api_key,
    #     run_config.api_secret,
    #     run_config.host_used,
    #     0.005,
    # )
    # wg_list.append(wg16)

    # wg17 = YYGateWangge(
    #     "FIL_USDT",
    #     50,
    #     "0.001",
    #     run_config.api_key,
    #     run_config.api_secret,
    #     run_config.host_used,
    #     0.004,
    # )
    # wg_list.append(wg17)

    wg18 = YYGateWangge(
        "PEPE_USDT",
        1,
        "0.000000001",
        run_config.api_key,
        run_config.api_secret,
        run_config.host_used,
        0.004,
    )
    wg_list.append(wg18)


    while 1:
        time.sleep(1)
        for w in wg_list:
            w.startSeeDealChance()
